import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { SnowToyModelEnum } from "../../../public/GameEnumConfig";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";
import Player from "../../player/Player";
/**
* 雪人部件
**/
export default class SnowToyModel extends DataItemModel {

	static CLASS_NAME: string = 'SnowToyModel'

	init(id, data) {
		super.init(id, data)
		this.setState(User.instance().getSnowToyState(this.ID))
	}

	needBuy() {
		let cost: number[] = this.getCostItem()
		return cost && cost.length > 0 && this.getState() != ItemState.GOT
	}

	setState(s: ItemState) {
		super.setState(s)
		//cc.log(' setState s ', s, ' ID ', this.ID)
		User.instance().setSnowToyState(this.ID, s)
	}

	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel()
	}
	
	getOpenLevel() {
		let num = this.data[SnowToyModelEnum.adge]
		return num ? num : 0
	}
	// icon
	getIcon() {
		return 'texture/snow_toy/' + this.data[SnowToyModelEnum.icon]
	}
	// 消费道具
	getCostItem() {
		return this.data[SnowToyModelEnum.costItem]
	}
	// 索引
	getIndex() {
		return this.data[SnowToyModelEnum.index]
	}



}